<!-- Displays "Challenge XXX" or "Challenge your friends" link -->
<% match = Match.find(sid) unless local_assigns.has_key?(:match) %>
<%match_placed =  (@user||current_user).bets.map{|b| b.match_id}.include?(sid.to_i)%>

<!--place challenge-->
<%if match_placed%>
    <%if u and u != current_user%>
		<%=link_to "Challenge<br/>" + u.name,"#",:clicktoshowdialog=>"dialog_#{sid}_#{u.id}"%>
		<%=render :partial=>'friends_bet/place_challenge',:locals=>{:sid=>sid,:u=>u}%>
   <%elsif u and u == current_user%>
		<%=link_to "Challenge your friends","#",:clicktoshowdialog=>"dialog_#{sid.to_s}" if Time.now < match.begin_at%></span>
		<%=render :partial=>'friends_bet/place_challenge',:locals=>{:sid=>sid,:u=>nil}%>
   <%else%>
		<%=link_to "Challenge your friends","#",:clicktoshowdialog=>"dialog_#{sid.to_s + (u.nil? ? "" : "_" + u.id.to_s)}" if Time.now < match.begin_at%></span>
		<%=render :partial=>'friends_bet/place_challenge',:locals=>{:sid=>sid,:u=>u}%>
   <%end%>
<%else%>
    <%if u and u != current_user%>
<%logger.error "----------------------------------"%>
<%logger.error u.to_s%>
<%logger.error u.id%>
<%logger.error u.facebook_id%>
<%logger.error sid%>
<%logger.error "----------------------------------"%>
       <%=link_to "Challenge<br/>" + u.name,"#",:onclick=>"showDialog('#{@call_back_url + "/friends_bet/gen_dialog?sid=" + sid.to_s + "&uid=" + u.id.to_s}');return false" if Time.now < match.begin_at and u and sid%></span>
    <%elsif u and u == current_user%>
       <%=link_to "Challenge your friends","#match_#{sid}",:onclick=>"showDialog('#{@call_back_url + "/friends_bet/gen_dialog?sid=" + sid.to_s}');return false" if Time.now < match.begin_at%></span>
    <%else%>
       <%=link_to "Challenge your friends","#match_#{sid}",:onclick=>"showDialog('#{@call_back_url + "/friends_bet/gen_dialog?sid=" + sid.to_s}');return false" if Time.now < match.begin_at%></span>
    <%end%>
<%end%>
